﻿@model Windvoice.Blog.Article
@using Windvoice.Blog
@using Windvoice.Library

@{
    ViewBag.Title = "Article Edit";
    Layout = "~/Areas/Manage/Views/Shared/_Layout.cshtml";
}

@section headSection{
    <link href="@Url.Content("~/Content/editor/plugin/code/prettify.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Content/js/jquery.validate.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Content/js/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Content/editor/xheditor.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Content/editor/plugin/code/prettify.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            var codePlugin = {
                Code: { c: 'btnCode', t: '插入代码', h: 1, e: function () {
                    var _this = this;
                    var htmlCode = '<div><select id="xheCodeType"><option value="html">HTML/XML</option><option value="js">Javascript</option><option value="css">CSS</option><option value="php">PHP</option><option value="java">Java</option><option value="py">Python</option><option value="pl">Perl</option><option value="rb">Ruby</option><option value="cs">C#</option><option value="c">C++/C</option><option value="vb">VB/ASP</option><option value="">其它</option></select></div><div><textarea id="xheCodeValue" wrap="soft" spellcheck="false" style="width:300px;height:100px;" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>';
                    var jCode = $(htmlCode), jType = $('#xheCodeType', jCode), jValue = $('#xheCodeValue', jCode), jSave = $('#xheSave', jCode);
                    jSave.click(function () {
                        _this.loadBookmark();
                        _this.pasteHTML('<pre class="prettyprint lang-' + jType.val() + '">' + _this.domEncode(jValue.val()) + '</pre>');
                        _this.hidePanel();
                        prettyPrint();
                        return false;
                    });
                    _this.showDialog(jCode);
                } //end of function
                } //end of code
            };
            $('#Content').xheditor({ height: 240, width: 500, plugins: codePlugin, upImgUrl: '/manage/article/upload', upImgExt: "jpg,png,gif" });

            prettyPrint();
        });
    </script>
}

<div class="pagetitle">
    <h2>编辑日志</h2>
    <div class="pagefunctions">
        @Html.ActionLink("返回列表", "index")
    </div>    
</div>

@using (Html.BeginForm("edit", "article", FormMethod.Post, new { @class = "dataform" }))
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>日志</legend>

        @Html.HiddenFor(model => model.ID)

        <div class="editor-label">
            @Html.LabelFor(model => model.Title)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Title, new { @class = "long" })
            @Html.ValidationMessageFor(model => model.Title)
        </div>
        
        <div class="editor-label">
            @Html.LabelFor(model => model.UniqueKey)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.UniqueKey, new { @class = "long" })
            @Html.ValidationMessageFor(model => model.UniqueKey)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Author)
        </div>
        <div class="editor-field">
            @Html.TextBoxFor(model => model.Author, new { @class = "short" })
            @Html.ValidationMessageFor(model => model.Author)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Weather)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.Weather, EnumHelper.ToSelectSource(typeof(WindvoiceWeatherCondition)))
            @Html.ValidationMessageFor(model => model.Weather)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.CategoryID)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.CategoryID, (IEnumerable<SelectListItem>)ViewBag.CategoryList)
            @Html.ValidationMessageFor(model => model.CategoryID)
        </div>
        
        <div class="editor-label">
            @Html.LabelFor(model => model.Content)
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Content)
            @Html.ValidationMessageFor(model => model.Content)
        </div>

        <p>
            <input class="submitbutton" type="submit" value="提交" />
        </p>
    </fieldset>
}